package com.blackbox.price.service;

import com.blackbox.price.entity.BbChildUser;
import com.blackbox.price.entity.BbUser;
import com.blackbox.price.mapper.BbChildUserMapper;
import com.blackbox.price.mapper.BbUserMapper;
import com.blackbox.price.mapper.common.VisionService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

/**
 * @Author: TWQ
 * @Description:
 * @Date: Created in 下午 21:59 2020/8/31 0024
 * @Modidied By: NO
 */
@Slf4j
@AllArgsConstructor
@Service("childUserService")
public class ChildUserService extends VisionService<BbChildUser> {

    @Resource
    private BbChildUserMapper bbChildUserMapper;

    public String addChildUser(BbChildUser childUser) {
        String uuid = UUID.randomUUID().toString();
        childUser.setId(uuid);
        bbChildUserMapper.insertSelective(childUser);
        return uuid;
    }

    public void setPidToChildUser(Integer pid, String[] childIds) {
        ArrayList<String> list = new ArrayList<String>(Arrays.asList(childIds)) ;
        log.error("list ========= {}", list);
        bbChildUserMapper.setPidToChildUser(pid, list);
    }

    public List<BbChildUser> queryChildListByPid(Integer pid) {
        return bbChildUserMapper.queryChildListByPid(pid);
    }

    public void deleteByPid(Integer pid) {
        bbChildUserMapper.deleteByPid(pid);
    }
}
